Backend uses \emph{message-bus architecure}. Core of the backend consists of
\emph{message bus}, \emph{messages}, \emph{message scheduler}, \emph{connection server} and \emph{message bus proxy}. All components of the backend are registered to message bus. Backend components communicate with each other by sending messages to the message bus. Also client processes can register them selves to the message bus via message-bus proxy. This way clients can trasparently communicate with backend components. Behind the curtains this communication is implemented using sockets, but clients doesn't need to know that. All they know is that they can send and receive messages. Figure \ref{fig:backend_arch} illustrates the architecture with a high level diagram. In the following sections we dicuss each component in more detail.

\begin{figure}[htb]
	\begin{center}
		\includegraphics[angle=0,scale=0.4]{diagrams/Backend/high_level.png}
		\caption{Backend architecure}
		\label{fig:backend_arch}
	\end{center}
\end{figure}

\subsubsection{Message bus}
Message bus is an object (type of \texttt{MessageBus}) that is resposible of transmitting messages between registered components. Every component has to implement \texttt{MessageHandler} interface so that it can receive messages properly. \texttt{MessageBus} has more also more advanced features than just trasmitting messages to all components. Every component has to determine message types that it is interested in. Components also determine the priority level for each message type. This way \texttt{MessageBus} doesn't have to transmit all messages to all components. Instead, it notifies only those components that are really interested in some particular message type. For more, \texttt{MessageBus} notifies those components in the order of priorites. For example, it is more critical to start recording as soon as possible than display notification bubble that recording has been started. That's why DVB-recorder tells the \texttt{MessageBus} that it has \texttt{VERY\_HIGH} priority for \texttt{START\_RECORDING} message type and similary notification system says that it has \texttt{VERY\_LOW} priority. Now, when \texttt{START\_RECORDING} message occurs, the \texttt{MessageBus} knows that it should first notify DVB-recorder and after that notification system. MessageBus is locked in such a way that only one message can occur at the time on the bus.

\subsubsection{Message}
Message is an object of \texttt{Message} type. These are the objects that are transmitted via \texttt{MessageBus}. Each Message has a message type and possibly some user data. Data part can contain arbitary data or it can be empty. Message types are defined in \texttt{MessageType} class. I suggest to take a look of that class, because it provides more information about the meaning of different message types. When component wants to send a \texttt{Message} to the \texttt{MessageBus} it needs to create a Message object and after that call \texttt{MessageBus}-object's \texttt{notifyMessage(message\_obj)} method.

\subsubsection{Message scheduler}
\texttt{MessageScheduler} object generates messages to the message bus. When backend starts, it registers message types and intervals to the \texttt{MessageScheduler}. After that messages are generated to the message bus in given time intervals. When message types are registered to the \texttt{MessageScheduler}, it creates a random time interval for each message type. This prevents all messages to be generated at the same time to the message bus. Random time interval is waited only the first time. After this messages are generated with given time interval. This scheduler is used for updateing guide and feed cache every now and then. It is also easy to add new features that require frequent updates.

\subsubsection{Connection server}
\texttt{ConnectionServer} listens incoming client connections and binds connected clients to the MessageBus. Every client is handled in it's own thread. This class is strictly binded to the MessageBusProxy class which we will discuss in next section.

\subsubsection{Message bus proxy}
\texttt{MessageBusProxy} object hides the complexity of sockets. \texttt{MessageBusProxy} is used in client process (Frontend for example) and it is abstraction of backend's \texttt{MessageBus}. In other words, client processes can act like backend components simply by using object of this class. This makes communication between components very easy no matter in which process the components are actually running.
